#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 3e5 + 10, INF = 0x3f3f3f3f;

struct node
{
    int x, y;
};

int d[4][2] = { 1,0,-1,0,0,1,0,-1 };
node st[N];
int tt = 0, now_step = 0;

void solve()
{
    int ans = 0;
    queue<pair<node, int>> q;
    int n, m; cin >> n >> m;
    vector<vector<char>> mp(n + 2, vector<char>(m + 2));
    for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++) {
        cin >> mp[i][j];
        if (mp[i][j] == '#') { q.push({ {i,j},0 }); }
    }

    auto f = [&](int x, int y) -> int {
        int cnt = 0;
        for (int i = 0;i < 4;i++) if (mp[x + d[i][0]][y + d[i][1]] == '#') cnt++;
        return cnt;
        };

    while (!q.empty()) {
        auto [now, step] = q.front();q.pop();
        ans++;

        if (step != now_step) {
            while (tt) {
                mp[st[tt].x][st[tt].y] = '#';
                tt--;
            }
            now_step++;
        }

        for (int i = 0;i < 4;i++) {
            int nx = now.x + d[i][0], ny = now.y + d[i][1];
            if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && mp[nx][ny] == '.' && f(nx, ny) == 1) {
                q.push({ { nx,ny },step + 1 });
                st[++tt] = { nx,ny };
            }
        }
    }

    // for (int i = 1;i <= n;i++) {
    //     for (int j = 1;j <= m;j++)
    //         cout << mp[i][j] << ' ';
    //     cout << '\n';
    // }

    cout << ans << '\n';
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}